import TWEEN from '@tweenjs/tween.js';

export default {
    install(Vue) {
        Vue.prototype.$tween = this;
        Vue.prototype.$tweener = TWEEN;
    },
    pause(tw) {
        tw.pause();
    },
    fade(target, to, during, delay, easing, onUpdate, onComplete) {
        if (!target || !to) {
            return;
        }
        if (during == null) {
            during = 260;
        }
        const tw = new TWEEN.Tween(target).to(to, during);
        if (delay) tw.delay(delay);
        tw.easing(easing || TWEEN.Easing.Linear.None);
        if (onUpdate) tw.onUpdate(onUpdate);
        if (onComplete) tw.onComplete(onComplete);
        tw.start();
        return tw;
    },
};
